/* GameObject.java
 * 
 * Alfred Olschnoegger
 * 22.05.2008
 */

package domain;

import java.util.Collection;
import java.util.LinkedList;

import domain.game.Game;
import domain.location.Position;
import domain.objectRules.ObjectRule;


/**
 * Abstract Class for Object on the Game Field
 *
 * @date 22.05.2008
 * @author Alfred Olschnoegger
 */

public abstract class GameObject implements Cloneable{
	
		// static part of this class
	private static int s_LastID = 0;
	
	/**
	 * internal class for ID generation
	 * 
	 * @return ne unique id for the rabbits
	 */
	synchronized private static int getNewID() {
		s_LastID++;
		return s_LastID;
	}
	
	
	// dynamic part of this class
	private int m_ID;
	protected Position m_Pos;
	protected boolean m_Active = true;
	protected int m_Age = 0;
	protected Collection<ObjectRule> m_Rules = new LinkedList<ObjectRule>();
	
	/**
	 * default constructor 
	 */
	public GameObject() {
		m_ID = GameObject.getNewID();
		m_Pos = null;
	}
	
	/**
	 * constructor with position setter
	 * @param pos position to start
	 */
	public GameObject(Position pos) {
		m_ID = GameObject.getNewID();
		m_Pos = pos;
	}
	
	/**
	 * 
	 * @return id of the game object
	 */
	public int getID() {
		return m_ID;
	}
	
	
	/**
	 * uses the game object on the field
	 * @param game 
	 * @param hunt 
	 */
	public abstract void use(Hunter hunt, Game game);
	
	
	/**
	 * applies the survival rules onto the object
	 * @param game game in which the object is existing
	 */
	public void applyRules(Game game) {
		for(ObjectRule r: m_Rules)
			r.use(this, game);
	}

	
	/**
	 * @return current position of the object
	 */
	public Position getPos() {
		return m_Pos;
	}

	/**
	 * 
	 * @param pos sets the position of the object
	 */
	public void setPos(Position pos) {
		m_Pos = pos;
	}
	
	/**
	 * @return true if the object is still not used
	 */
	public boolean isActive() {
		// TODO synchronisation
		return m_Active;
	}

	public int getAge() {
		return m_Age;
	}

	public void setAge(int age) {
		m_Age = age;
	}
	
	public void setActive(boolean active) {
		m_Active = active;
	}
	
	public void addRule(ObjectRule rule) {
		m_Rules.add(rule);
	}
	
	public abstract GameObject clone();
}


// end of GameObject.java
